package com.youshuit.designmodedemo.controller;

import java.math.BigDecimal;

import com.youshuit.designmodedemo.enumx.PayType;
import com.youshuit.designmodedemo.module.po.PayResult;
import com.youshuit.designmodedemo.factory.PaymentFactory;
import com.youshuit.designmodedemo.module.vo.PayRequestVO;
import com.youshuit.designmodedemo.service.IPaymentService;

public class FactoryPattern {

    // public PayResult pay(PayRequestVO payRequest) {
    //     IPaymentService paymentService = PaymentFactory.creatPayment(payRequest.getPayTypeCode());
    //     return paymentService.pay(payRequest.getOrderId(), payRequest.getAmount());
    // }

    // public RefundResult refund(PayRequestVO payRequest) {
    //     IPaymentService paymentService = PaymentFactory.creatPayment(payRequest.getPayTypeCode());
    //     return paymentService.refund(payRequest.getOrderId(), payRequest.getAmount());
    // }

    // public PayStatus queryPayStatus(PayRequestVO payRequest) {
    //     IPaymentService paymentService = PaymentFactory.creatPayment(payRequest.getPayTypeCode());
    //     return paymentService.queryPayStatus(payRequest.getOrderId());
    // }
   public static void main(String[] args) {
        testWechatPay();

        testAliPay();

        testCmbPay();
    }


    private static void testWechatPay() {
        PayRequestVO payRequest = new PayRequestVO();
        payRequest.setOrderId("WX123456");
        payRequest.setAmount(new BigDecimal(89));
        payRequest.setPayTypeCode(PayType.WECHAT.getCode());

        IPaymentService paymentService = PaymentFactory.creatPayment(payRequest.getPayTypeCode());
        PayResult payResult = paymentService.pay(payRequest.getOrderId(), payRequest.getAmount());
        System.out.println(payResult);
    }

     private static void testAliPay() {
        PayRequestVO payRequest = new PayRequestVO();
        payRequest.setOrderId("ALIPAY123456");
        payRequest.setAmount(new BigDecimal(100));
        payRequest.setPayTypeCode(PayType.ALIPAY.getCode());

        IPaymentService paymentService = PaymentFactory.creatPayment(payRequest.getPayTypeCode());
        PayResult payResult = paymentService.pay(payRequest.getOrderId(), payRequest.getAmount());
        System.out.println(payResult);
    }

    private static void testCmbPay() {
        PayRequestVO payRequest = new PayRequestVO();
        payRequest.setOrderId("CMB123456");
        payRequest.setAmount(new BigDecimal(201));
        payRequest.setPayTypeCode(PayType.CMB.getCode());

        IPaymentService paymentService = PaymentFactory.creatPayment(payRequest.getPayTypeCode());
        PayResult payResult = paymentService.pay(payRequest.getOrderId(), payRequest.getAmount());
        System.out.println(payResult);
    }
}
